﻿#pragma once


#ifdef AS_REDIS
#include <stdint.h>
#include <stdlib.h>
#include <string>

namespace as
{
namespace db
{

enum class ValueType : uint8_t
{
	REDIS_VALUE_NIL = 0,
	REDIS_VALUE_INTEGER = 1,
	REDIS_VALUE_BOOL,
	REDIS_VALUE_FLOAT,
	REDIS_VALUE_DOUBLE,
	REDIS_VALUE_STRING,
};

class RedisValue
{
	union _VAL
	{
		uint64_t ul = 0;
		double d;
		struct  
		{
			RedisValue **list;
			unsigned int len;
		};
	};

public:
	operator int64_t() const;
	operator uint64_t() const;
	operator double() const;
	operator float() const;
	operator int() const;
	operator unsigned int() const;
	operator const char *() const;
	
public:
	RedisValue &operator=(double val);
	RedisValue &operator=(int val);
	RedisValue &operator=(unsigned int val);
	RedisValue &operator=(int64_t val);
	RedisValue &operator=(uint64_t val);
	RedisValue &operator=(float val);
	RedisValue &operator=(const char *val);
	RedisValue &operator=(const std::string &val);

public:
	inline void Clear();
	inline std::string tostring();
private:
	ValueType type_{ ValueType::REDIS_VALUE_NIL };
	_VAL val_;
	std::string str_val_;
};


}
}



#endif


